2 -- Configuration de Garradin
7 -- On stocke ici les ID de catégorie de compta correspondant aux types spéciaux
8 -- compta_categorie_cotisations => id_categorie
9 -- compta_categorie_dons => id_categorie
11 CREATE TABLE membres_categories
12 -- Catégories de membres
14 id INTEGER PRIMARY KEY,
18 droit_wiki
INT DEFAULT 1,
19 droit_membres
INT DEFAULT 1,
20 droit_compta
INT DEFAULT 1,
21 droit_inscription
INT DEFAULT 0,
22 droit_connexion
INT DEFAULT 1,
23 droit_config
INT DEFAULT 0,
26 id_cotisation_obligatoire
INTEGER NULL REFERENCES cotisations (id)
30 -- Table dynamique générée par l'application
31 -- voir class.champs_membres.php
33 CREATE TABLE cotisations
34 -- Types de cotisations et activités
36 id INTEGER PRIMARY KEY,
37 id_categorie_compta
INTEGER NULL, -- NULL si le type n'est pas associé automatiquement à la compta
39 intitule
TEXT NOT NULL,
40 description
TEXT NULL,
41 montant
REAL NOT NULL,
43 duree
INTEGER NULL, -- En jours
44 debut
TEXT NULL, -- timestamp
47 FOREIGN KEY (id_categorie_compta
) REFERENCES compta_categories (id)
50 CREATE TABLE cotisations_membres
51 -- Enregistrement des cotisations et activités
53 id INTEGER NOT NULL PRIMARY KEY,
54 id_membre
INTEGER NOT NULL REFERENCES membres (id),
55 id_cotisation
INTEGER NOT NULL REFERENCES cotisations (id),
57 date TEXT NOT NULL DEFAULT CURRENT_DATE
60 CREATE UNIQUE INDEX cm_unique
ON cotisations_membres (id_membre
, id_cotisation
, date);
62 CREATE TABLE membres_operations
63 -- Liaision des enregistrement des paiements en compta
65 id_membre
INTEGER NOT NULL REFERENCES membres (id),
66 id_operation
INTEGER NOT NULL REFERENCES compta_journal (id),
67 id_cotisation
INTEGER NULL REFERENCES cotisations_membres (id),
69 PRIMARY KEY (id_membre
, id_operation
)
73 -- Rappels de devoir renouveller une cotisation
75 id INTEGER PRIMARY KEY,
76 id_cotisation
INTEGER NOT NULL REFERENCES cotisations (id),
78 delai
INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
84 CREATE TABLE rappels_envoyes
85 -- Enregistrement des rappels envoyés à qui et quand
87 id INTEGER PRIMARY KEY,
89 id_membre
INTEGER NOT NULL REFERENCES membres (id),
90 id_cotisation
INTEGER NOT NULL REFERENCES cotisations (id),
92 date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
94 media
INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre
101 CREATE TABLE wiki_pages
104 id INTEGER PRIMARY KEY,
105 uri TEXT, -- URI unique (équivalent NomPageWiki)
107 date_creation
TEXT DEFAULT CURRENT_TIMESTAMP,
108 date_modification
TEXT DEFAULT CURRENT_TIMESTAMP,
109 parent
INTEGER DEFAULT 0, -- ID de la page parent
110 revision
INTEGER DEFAULT 0, -- Numéro de révision (commence à 0 si pas de texte, +1 à chaque changement du texte)
111 droit_lecture
INTEGER DEFAULT 0, -- Accès en lecture (-1 = public [site web], 0 = tous ceux qui ont accès en lecture au wiki, 1+ = ID de groupe)
112 droit_ecriture
INTEGER DEFAULT 0 -- Accès en écriture (0 = tous ceux qui ont droit d'écriture sur le wiki, 1+ = ID de groupe)
115 CREATE UNIQUE INDEX wiki_uri
ON wiki_pages (uri);
117 CREATE VIRTUAL
TABLE wiki_recherche
USING fts4
118 -- Table dupliquée pour chercher une page
120 id INT PRIMARY KEY NOT NULL, -- Clé externe obligatoire
122 contenu
TEXT, -- Contenu de la dernière révision
123 FOREIGN KEY (id) REFERENCES wiki_pages(id)
126 CREATE TABLE wiki_revisions
127 -- Révisions du contenu des pages
129 id_page
INTEGER NOT NULL,
135 modification
TEXT, -- Description des modifications effectuées
136 chiffrement
INTEGER DEFAULT 0, -- 1 si le contenu est chiffré, 0 sinon
137 date TEXT DEFAULT CURRENT_TIMESTAMP,
139 PRIMARY KEY(id_page
, revision
),
140 FOREIGN KEY (id_page
) REFERENCES wiki_pages (id), -- Clé externe obligatoire
141 FOREIGN KEY (id_auteur
) REFERENCES membres (id) -- Clé externe non-obligatoire (peut être supprimée après en cas de suppression de membre)
144 CREATE INDEX wiki_revisions_id_page
ON wiki_revisions (id_page
);
145 CREATE INDEX wiki_revisions_id_auteur
ON wiki_revisions (id_auteur
);
147 -- Triggers pour synchro avec table wiki_pages
148 CREATE TRIGGER wiki_recherche_delete
AFTER DELETE ON wiki_pages
150 DELETE FROM wiki_recherche
WHERE id = old.
id;
153 CREATE TRIGGER wiki_recherche_update
AFTER UPDATE OF id, titre
ON wiki_pages
155 UPDATE wiki_recherche
SET id = new.
id, titre
= new.titre
WHERE id = old.
id;
158 -- Trigger pour mettre à jour le contenu de la table de recherche lors d'une nouvelle révision
159 CREATE TRIGGER wiki_recherche_contenu_insert
AFTER INSERT ON wiki_revisions
WHEN new.chiffrement
!= 1
161 UPDATE wiki_recherche
SET contenu
= new.contenu
WHERE id = new.id_page
;
164 -- Si le contenu est chiffré, la recherche n'affiche pas de contenu
165 CREATE TRIGGER wiki_recherche_contenu_chiffre
AFTER INSERT ON wiki_revisions
WHEN new.chiffrement
= 1
167 UPDATE wiki_recherche
SET contenu
= '' WHERE id = new.id_page
;
171 CREATE TABLE wiki_fichiers (
172 id INTEGER PRIMARY KEY,
173 id_page INTEGER NOT NULL,
177 FOREIGN KEY (id_page) REFERENCES wiki_pages (id) -- Clé externe obligatoire
180 CREATE INDEX wiki_fichiers_id_page ON wiki_fichiers (id_page);
182 CREATE TABLE wiki_suivi
185 id_membre INTEGER NOT NULL,
186 id_page INTEGER NOT NULL,
188 PRIMARY KEY (id_membre, id_page),
190 FOREIGN KEY (id_page) REFERENCES wiki_pages (id), -- Clé externe obligatoire
191 FOREIGN KEY (id_membre) REFERENCES membres (id) -- Clé externe obligatoire
199 CREATE TABLE compta_exercices
202 id INTEGER PRIMARY KEY,
204 libelle
TEXT NOT NULL,
206 debut
TEXT NOT NULL DEFAULT CURRENT_DATE,
207 fin
TEXT NULL DEFAULT NULL,
209 cloture
INTEGER NOT NULL DEFAULT 0
213 CREATE TABLE compta_comptes
216 id TEXT PRIMARY KEY, -- peut contenir des lettres, eg. 53A, 53B, etc.
217 parent
TEXT NOT NULL DEFAULT 0,
219 libelle
TEXT NOT NULL,
221 position INTEGER NOT NULL, -- position actif/passif/charge/produit
222 plan_comptable
INTEGER NOT NULL DEFAULT 1, -- 1 = fait partie du plan comptable, 0 = a été ajouté par l'utilisateur
223 desactive
INTEGER NOT NULL DEFAULT 0 -- 1 = compte historique désactivé
226 CREATE INDEX compta_comptes_parent
ON compta_comptes (parent
);
228 CREATE TABLE compta_comptes_bancaires
233 banque
TEXT NOT NULL,
238 FOREIGN KEY(id) REFERENCES compta_comptes(id)
241 CREATE TABLE compta_journal
242 -- Journal des opérations comptables
244 id INTEGER PRIMARY KEY,
246 libelle
TEXT NOT NULL,
248 numero_piece
TEXT, -- N° de pièce comptable
252 date TEXT DEFAULT CURRENT_DATE,
253 moyen_paiement
TEXT DEFAULT NULL,
254 numero_cheque
TEXT DEFAULT NULL,
256 compte_debit
TEXT, -- N° du compte dans le plan
257 compte_credit
TEXT, -- N° du compte dans le plan
259 id_exercice
INTEGER NULL DEFAULT NULL, -- En cas de compta simple, l'exercice est permanent (NULL)
260 id_auteur
INTEGER NULL,
261 id_categorie
INTEGER NULL, -- Numéro de catégorie (en mode simple)
263 FOREIGN KEY(moyen_paiement
) REFERENCES compta_moyens_paiement(code
),
264 FOREIGN KEY(compte_debit
) REFERENCES compta_comptes(id),
265 FOREIGN KEY(compte_credit
) REFERENCES compta_comptes(id),
266 FOREIGN KEY(id_exercice
) REFERENCES compta_exercices(id),
267 FOREIGN KEY(id_auteur
) REFERENCES membres(id),
268 FOREIGN KEY(id_categorie
) REFERENCES compta_categories(id)
271 CREATE INDEX compta_operations_exercice
ON compta_journal (id_exercice
);
272 CREATE INDEX compta_operations_date
ON compta_journal (date);
273 CREATE INDEX compta_operations_comptes
ON compta_journal (compte_debit
, compte_credit
);
274 CREATE INDEX compta_operations_auteur
ON compta_journal (id_auteur
);
276 CREATE TABLE compta_moyens_paiement
277 -- Moyens de paiement
279 code
TEXT PRIMARY KEY,
283 --INSERT INTO compta_moyens_paiement (code, nom) VALUES ('AU', 'Autre');
284 INSERT INTO compta_moyens_paiement (code
, nom
) VALUES ('CB', 'Carte bleue');
285 INSERT INTO compta_moyens_paiement (code
, nom
) VALUES ('CH', 'Chèque');
286 INSERT INTO compta_moyens_paiement (code
, nom
) VALUES ('ES', 'Espèces');
287 INSERT INTO compta_moyens_paiement (code
, nom
) VALUES ('PR', 'Prélèvement');
288 INSERT INTO compta_moyens_paiement (code
, nom
) VALUES ('TI', 'TIP');
289 INSERT INTO compta_moyens_paiement (code
, nom
) VALUES ('VI', 'Virement');
291 CREATE TABLE compta_categories
292 -- Catégories pour simplifier le plan comptable
294 id INTEGER PRIMARY KEY,
295 type INTEGER DEFAULT 1, -- 1 = recette, -1 = dépense, 0 = autre (utilisé uniquement pour l'interface)
297 intitule
TEXT NOT NULL,
300 compte
TEXT NOT NULL, -- Compte affecté par cette catégorie
302 FOREIGN KEY(compte
) REFERENCES compta_comptes(id)
308 officiel
INTEGER NOT NULL DEFAULT 0,
313 version TEXT NOT NULL,
314 menu
INTEGER NOT NULL DEFAULT 0,